#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <pthread.h>

void* test_thread(void* arg)
{
	char buff[128];
	int size = (int)(long)arg;
	size += 1;

	void* p1 = malloc(10000 * size);
	void* p2 = malloc(100000 * size);
	void* p3 = malloc(1000000 * size);
	void* p4 = malloc(10000000 * size);

	memset(p1, 'U', 10000 * size);
	free(p2);
	memset(p3, 'U', 1000000 * size);
	free(p4);
	// printf("%ld %ld\n", (long)p2, (long)p3);

	snprintf(buff, sizeof(buff), "malloc:%p,%p,%p,%p\n", p1, p2, p3, p4);

	return 0;
}

int main()
{
#if 1
	int i = 0;
	pthread_t tid[5];
	for (i = 0; i < 5; i++) {
		pthread_create(&tid[i], NULL, test_thread, (void*)(long)i);
	}

	for (i = 0; i < 5; i++) {
		pthread_join(tid[i], NULL);
	}
#else
	test_thread((void*)(long)0);
	test_thread((void*)(long)1);
	test_thread((void*)(long)2);
#endif
	return 0;
}
